﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FindIt.Domain.Contracts;
using FindIt.Domain.Models;
using FindIt.Data;

namespace FindIt.Domain {
    public class UserServices : IUserServices {
        private readonly IContributorRepository _contributorRepository;

        public UserServices(IContributorRepository contributorRepository) {
            this._contributorRepository = contributorRepository;
        }
        public bool ValidateUser(string usernameOrEmail, string password) {
            var contributor = _contributorRepository.GetContributor(usernameOrEmail);

            if (password.Equals(contributor.Password))
                return true;

            return false;
        }
        public User RegisterUser(User registerUser) {
            return null;
        }

        public User GetAuthenticatedUser(string email) {
            var user = _contributorRepository.GetContributor(email);

            if (user != null)
                return ToServiceUser(user);

            return null;
        }

        public bool ChangePassword(string usernameOrEmail, string newPassword, string oldPassword) {
            return true;
        }
        public void UpdateUser(User updatedUser) { }

        public bool DeleteUser(User deletedUser) {
            return true;
        }

        public User ToServiceUser(Model.Contributor dataUser) {
            User user = new User() {
                Id = dataUser.Id,
                Email = dataUser.Email,
                Password = dataUser.Password,
                ScreenName = dataUser.ScreenName,
                RealName = dataUser.RealName
            };

            return user;
        }
    }
}
